package o;

import java.nio.charset.Charset;
import java.util.Locale;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import javax.annotation.Nullable;

public final class fup {
    private static final Pattern ˎ = Pattern.compile("([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)/([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)");
    private static final Pattern ॱ = Pattern.compile(";\\s*(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)=(?:([a-zA-Z0-9-!#$%&'*+.^_`{|}~]+)|\"([^\"]*)\"))?");
    @Nullable
    private final String ʽ;
    private final String ˊ;
    private final String ˋ;
    private final String ˏ;

    private fup(String str, String str2, String str3, @Nullable String str4) {
        this.ˋ = str;
        this.ˏ = str2;
        this.ˊ = str3;
        this.ʽ = str4;
    }

    public static fup ˎ(String str) {
        Matcher matcher = ˎ.matcher(str);
        if (matcher.lookingAt()) {
            String toLowerCase = matcher.group(1).toLowerCase(Locale.US);
            String toLowerCase2 = matcher.group(2).toLowerCase(Locale.US);
            Matcher matcher2 = ॱ.matcher(str);
            int end = matcher.end();
            String str2 = null;
            int i = end;
            while (i < str.length()) {
                matcher2.region(i, str.length());
                if (matcher2.lookingAt()) {
                    String group = matcher2.group(1);
                    if (group != null && group.equalsIgnoreCase("charset")) {
                        group = matcher2.group(2);
                        if (group == null) {
                            group = matcher2.group(3);
                        } else if (group.startsWith("'") && group.endsWith("'") && group.length() > 2) {
                            group = group.substring(1, group.length() - 1);
                        }
                        if (str2 == null || group.equalsIgnoreCase(str2)) {
                            str2 = group;
                        } else {
                            throw new IllegalArgumentException("Multiple charsets defined: \"" + str2 + "\" and: \"" + group + "\" for: \"" + str + '\"');
                        }
                    }
                    i = matcher2.end();
                } else {
                    throw new IllegalArgumentException("Parameter is not formatted correctly: \"" + str.substring(i) + "\" for: \"" + str + '\"');
                }
            }
            return new fup(str, toLowerCase, toLowerCase2, str2);
        }
        throw new IllegalArgumentException("No subtype found for: \"" + str + '\"');
    }

    @Nullable
    public static fup ॱ(String str) {
        try {
            return ˎ(str);
        } catch (IllegalArgumentException e) {
            return null;
        }
    }

    public String ˏ() {
        return this.ˏ;
    }

    @Nullable
    public Charset ॱ() {
        return ˏ(null);
    }

    @Nullable
    public Charset ˏ(@Nullable Charset charset) {
        try {
            if (this.ʽ != null) {
                charset = Charset.forName(this.ʽ);
            }
        } catch (IllegalArgumentException e) {
        }
        return charset;
    }

    public String toString() {
        return this.ˋ;
    }

    public boolean equals(@Nullable Object obj) {
        return (obj instanceof fup) && ((fup) obj).ˋ.equals(this.ˋ);
    }

    public int hashCode() {
        return this.ˋ.hashCode();
    }
}
